﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UIData {
    private Dictionary<string, string> stringDataDic;
    private Dictionary<string, TextUIElement> bindDIc;

    public UIData() {
        stringDataDic = new Dictionary<string, string>();
        bindDIc = new Dictionary<string, TextUIElement>();
    }

    public void Bind(string name, TextUIElement element) {
        if (bindDIc.ContainsKey(name))
        {
            bindDIc[name] = element;
        }
        else
        {
            bindDIc.Add(name, element);
        }
    }

    public void Set(string name, int value) {
        Set(name, value.ToString());
    }
    public void Set(string name, string value) {
        if (stringDataDic.ContainsKey(name))
        {
            stringDataDic[name] = value;
        }
        else {
            stringDataDic.Add(name, value);
        }
        bindDIc[name].SetText(value);
    }

    public string Get(string name) {
        if (stringDataDic.ContainsKey(name))
        {
            return stringDataDic[name];
        }
        else {
            Debug.LogError("UIData中不存在变量 " + name + " ");
            return "";
        }
    }
}
